/**
 * 敌人管理
 */
cc.Class({
    extends: cc.Component,

    properties: {
        /**
         * 奖励物品位置
         */
        rewardPositions: {
            default: [],
            type: cc.Node,
            tooltip: "奖励物品位置"
        }
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
    },

    start () {

    },

    update (dt) {
        //奖励物品旋转
        if (this._rewardItem) {
            this._rewardItem.rotation = -this.node.rotation - this.node.parent.rotation;
        }
        
    },

    /**
     * 生成一个奖励物品
     * @param {cc.Prefab} rewardPrefab 奖励物品预设
     */
    createReward (rewardPrefab) {
        if (this.rewardPositions.length == 0) return; 
        var posIndex = Math.floor(cc.random0To1() * this.rewardPositions.length);
        var clone = cc.instantiate(rewardPrefab);
        clone.parent = this.rewardPositions[posIndex];
        clone.setPosition(cc.v2(0,0));
        this._rewardItem = clone;
    }
});
